﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Xource.Helper
{
    internal static class XourceMonitor
    {
        static readonly string _Filter = "*.xlsx";
        static FileSystemWatcher watcher;
        

        public static void Initialize()
        {
            if (watcher == null)
            {
                watcher = new FileSystemWatcher(Path.GetDirectoryName(XourceHandler.GetLocalFile()), _Filter);
                watcher.Deleted += ReInitilizeContent;
                watcher.Changed += ReInitilizeContent;
                watcher.EnableRaisingEvents = true;
            }
        }

        static void ReInitilizeContent(object sender, FileSystemEventArgs e)
        {
            if(e.Name.EndsWith(XourceHandler._ContentFileName))
            {
                XourceHandler.ReInitialize();
            }
        }
    }
}
